package com.itheima.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * CTassName: TimeAspect
 * Package: com.itheima.aspect
 * Description:
 *
 * @Author xw
 * @Create 2023/11/9 15:51
 * @Version 1.0
 */
@Component
@Aspect
@Slf4j
public class TimeAspect {

    @Around("execution(* com.itheima.service.*.*.*(..))")
    public Object recordTime(ProceedingJoinPoint pjp) throws Throwable {

        long l = System.currentTimeMillis();

        // 执行原始方法
        Object proceed = pjp.proceed();

        long e = System.currentTimeMillis();
        // 获取执行方法的名称
        log.info(pjp.getSignature() + "执行消耗时间" + (e - l));
        return proceed;

    }
}
